<?php

class mdl_reff_unit extends CI_Model{

	function __construct(){
		parent::__construct();
	}

	function get_all(){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('reff_unit');
		return $this->db->get();

	}

	function get_by_like($id,$escape_self){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('reff_unit');
		$this->db->like('kd_unit', $id, 'after');
		$this->db->where('kd_unit !=', $id . $escape_self);
		return $this->db->get();
	}

	function get_by_id($id){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('reff_unit');
		$this->db->like('kd_unit', $id, 'after');
		return $this->db->get();
	}

	function get_by_kd_unit($kd_unit){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('reff_unit');
		$this->db->like('kd_unit', $kd_unit);
		return $this->db->get();
	}

	function get_select_reff_unit($d=""){
		$name = isset($d['name'])?$d['name']:'';
		$id = isset($d['id'])?$d['id']:'';
		$class = isset($d['class'])?$d['class']:'';
		$value = isset($d['value'])?$d['value']:'';

		$this->db->flush_cache();
		$this->db->from('reff_unit');
		$this->db->order_by('kd_unit');

		$res = $this->db->get();

		$out = '';
		$out .= '<option value="" selected="selected">-- Pilih --</option>';
		foreach($res->result() as $r){
			if($r->kd_unit == trim($value)){
				$out .= '<option value="'.$r->kd_unit.'" selected="selected">'.$r->jbt_unit.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_unit.'">'.$r->jbt_unit.'</option>';
			}
		}


		return $out;
	}


	function get_user_reff_unit($d=""){
		$name = isset($d['name'])?$d['name']:'';
		$id = isset($d['id'])?$d['id']:'';
		$class = isset($d['class'])?$d['class']:'';
		$value = isset($d['value'])?$d['value']:'';

		$this->db->flush_cache();
		$this->db->select('reff_unit.kd_unit,reff_unit.jbt_unit,t_admin.username,t_admin.id');
		$this->db->from('reff_unit');
		$this->db->join('t_admin','reff_unit.kd_unit=t_admin.kd_unit');
		$this->db->order_by('kd_unit');

		$res = $this->db->get();

		$out = '';
		$out .= '<option value="" selected="selected">-- Pilih --</option>';
		foreach($res->result() as $r){
			if($r->kd_unit == trim($value)){
				$out .= '<option value="'.$r->id.'" selected="selected">'.$r->username. ' - ' .$r->jbt_unit.'</option>';
			}else{
				$out .= '<option value="'.$r->id.'">'.$r->username. ' - ' .$r->jbt_unit.'</option>';
			}
		}


		return $out;
	}

	function get_t_admin($id,$escape_self){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('t_admin');
		$this->db->like('kd_unit', $id, 'after');
		$this->db->where('kd_unit !=', $id . $escape_self);
		return $this->db->get();
	}

	function get_t_admin_for_staff($id,$escape_self){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('t_admin');
		$this->db->like('kd_unit', $id, 'after');
		$this->db->where('kd_unit !=', $id . '00');
		return $this->db->get();
	}

	function get_t_admin_by_id($id){
		$this->db->flush_cache();
		$this->db->select('*');
		$this->db->from('t_admin');
		$this->db->where('id', $id);
		return $this->db->get();
	}



}


?>